<?php
class erpapi_shop_matrix_pinduoduo_response_aftersalev2 extends erpapi_shop_response_aftersalev2 {

    protected function _formatAddParams($params){
        $sdf = parent::_formatAddParams($params);
        $pinduoduoSdf = array(
            'oid'               => $params['oid'],
            'cs_status'         => $params['cs_status'],
            'seller_nick'       => $params['seller_nick'],
            'payment_id'        => $params['payment_id'],
            'desc'              => $params['descd'],
        );
        return array_merge($sdf, $pinduoduoSdf);
    }
    protected function _getAddType($sdf) {
        if ($sdf['refund_type'] == 'return') {
            if ($sdf['has_good_return'] == 'true') {//需要退货才更新为售后单
                if (in_array($sdf['order']['ship_status'],array('0'))) {
                    #有退货，未发货的,做退款
                    return 'refund';
                }else{
                    #有退货，已发货的,做售后
                    return 'returnProduct';
                }
            }else{
                return 'refund';
            }
        }elseif($sdf['refund_type'] == 'reship'){
            #退货单
            return 'reship';
        }else{
            #无退货的，直接退款(包括refund_type=apply)
            return 'refund';
        }
    }

    protected function _formatAddItemList($sdf, $convert = array()) {
        if($sdf['refund_type'] == 'reship') {
            return array();
        }
        $convert = array(
            'sdf_field'=>'oid',
            'order_field'=>'oid',
            'default_field'=>'outer_id'
        );
        return parent::_formatAddItemList($sdf, $convert);
    }

    # 拼多多退款申请附加
    protected function _refundApplyAdditional($sdf) {
        $ret = array(
            'model' => 'refund_apply_pinduoduo',
            'data' => array(
                'shop_id'               => $sdf['shop_id'],
                'oid'                   => $sdf['oid'],
                'cs_status'             => $sdf['cs_status'],
                'seller_nick'           => $sdf['seller_nick'],
                'buyer_nick'            => $sdf['buyer_nick'],
                'has_good_return'       => $sdf['has_good_return'],
                'payment_id'            => $sdf['payment_id'],
                'refund_fee'            => $sdf['refund_fee'],
                'operation_constraint'  => $sdf['operation_constraint']
            )
        );
        return $ret;
    }

    # 拼多多售后申请附加
    protected function _returnProductAdditional($sdf) {
        $ret = array(
            'model' => 'return_product_pinduoduo',
            'data' => array(
                'shop_id'               => $sdf['shop_id'],
                'shipping_type'         => $sdf['shipping_type'],
                'cs_status'             => $sdf['cs_status'],
                'buyer_nick'            => $sdf['buyer_nick'],
                'seller_nick'           => $sdf['seller_nick'],
                'has_good_return'       => $sdf['has_good_return'],
                'payment_id'            => $sdf['payment_id'],
                'good_return_time'      => $sdf['good_return_time'],
                'oid'                   => $sdf['oid'],
                'refund_fee'            => $sdf['refund_fee'],
                'operation_constraint'  => $sdf['operation_constraint']
            )
        );
        return $ret;
    }
}
